package com.jxc.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jxc.entity.Staff;

public class AuthenticationFilter implements Filter {

	public void destroy() {
		// TODO Auto-generated method stub
	}
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
	
         /*  HttpServletRequest req=(HttpServletRequest)request;
           HttpServletResponse res=(HttpServletResponse)response;
		   String path=req.getServletPath();
		   String pathName=path.substring(path.indexOf(".")+1);
	        if(!pathName.endsWith("action")&&!pathName.endsWith("jsp")){
	        	
	        	  chain.doFilter(request, response);
	        }
	        else if(path.endsWith("/staffAction_login.action")||path.endsWith("/staffAction_checkCode.action")||path.endsWith("/login.jsp")){
			   chain.doFilter(request, response);
		   }
		   else{
			    HttpSession session=req.getSession();
			    Staff staff=(Staff)session.getAttribute("userinfo");
			    if(staff==null){
			    	//req.getRequestDispatcher("../login.jsp").forward(req,response);
			    	res.sendRedirect("/JXC/login.jsp");
			    }
			    else{
			    	 chain.doFilter(request, response);
			    } 
		   }*/
		 chain.doFilter(request, response);
	}
	public void init(FilterConfig arg0) throws ServletException {
	}
}
